﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Configuration;


public partial class Default2 : System.Web.UI.Page
{
    public string tabId = "0";

    /// <summary>
    /// Default function when page is loaded
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    /// <summary>
    /// set the public variable to 1, is needed for jquery tabs
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ChangePasswordPushButton_Click(object sender, EventArgs e)
    {
        tabId = "1";
    }

    /// <summary>
    /// Set the public variable to 2, is needed for jquery tabs
    /// Sets the forgotpasswordquestion and answer for the user 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void saveEmailQuestion_Click(object sender, EventArgs e)
    {
        tabId = "2";

        MembershipUser u = Membership.GetUser(User.Identity.Name);

        string email = Email.Text;
        if (!string.IsNullOrEmpty(email.Trim()))
        {
            try
            {
                u.Email = Email.Text;
                Membership.UpdateUser(u);
            }
            catch (Exception ex)
            {
                OmniaLogger.Log.Error("Setting emailaddress failed: ", ex);
            }
        }
      
        try
        {
            Boolean result = u.ChangePasswordQuestionAndAnswer(Password.Text,
                                              Question.Text,
                                              Answer.Text);
        }
        catch (Exception ex)
        {
            OmniaLogger.Log.Error("Setting question and answer failed: ", ex);
        }
    }
}
